home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / exec.swg / 0009_Change the MASTER Env.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-02  |  1.6 KB  |  54 lines

  1. {
  2. KELLY SMALL
  3.  
  4. >Does anyone know how to change the "master" environment?  I want to have my
  5. >program change the dos prompt and have it be there after my program ends.
  6. >DOS's stupid little batch language can do it, so there must be a way.
  7.  
  8. Here's a procedure that should do it from TeeCee:
  9. }
  10.  
  11. procedure InitNewPrompt;
  12. {-set up a new prompt for shelling to dos}
  13. type
  14.   _2karray = array[1..2048] of byte;
  15.   SegPtr   = ^_2karray;
  16. const
  17.   NewPrompt : string = ('PROMPT=Type EXIT to return to program$_$p$g'+#0);
  18. var
  19.   EnvSegment,
  20.   NewEnvSeg   : word;
  21.   PtrSeg,
  22.   NewEnv      : SegPtr;
  23. begin
  24.   EnvSegment := memw[prefixseg:$2C];
  25.   {-this gets the actual starting segment of the current program's env}
  26.  
  27.   PtrSeg := ptr(pred(EnvSegment), 0);
  28.   {-The segment of the program's MCB - (Memory control block) }
  29.  
  30.   getmem(NewEnv, 1072 + length(NewPrompt));
  31.   {-Allocate heap memory and allow enough room for a dummy mcb }
  32.  
  33.   if ofs(NewEnv^) <> 0 then
  34.     NewEnvSeg := seg(NewEnv^) + 2
  35.   else
  36.     NewEnvSeg := succ(seg(NewEnv^));
  37.   {-Force the new environment to start at paragraph boundary}
  38.  
  39.   move(PtrSeg^, mem[pred(NewEnvSeg) : 0], 16);
  40.   {-copy the old mcb and force to paragraph boundary}
  41.  
  42.   memw[pred(NewEnvSeg) : 3] := (1072 + length(NewPrompt)) shr 4;
  43.   {-Alter the environment length by changing the dummy mcb}
  44.  
  45.   move(NewPrompt[1], memw[NewEnvSeg : 0], length(NewPrompt));
  46.   {-install new prompt}
  47.  
  48.   memw[prefixseg:$2C] := NewEnvSeg;
  49.   {-let the program know where the new env is}
  50.  
  51.   move(mem[EnvSegment : 0], mem[NewEnvSeg : length(NewPrompt)], 1024);
  52.   {-shift the old env to the new area}
  53. end;
  54.